package com.ruoyi.weixin.mp.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.weixin.mp.entity.WxAccount;
import com.ruoyi.weixin.mp.service.WxAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author anan.
 * @version 1.0
 * @create 2021-05-28 10-27
 */
@RestController
@RequestMapping("/manage/wxAccount")
@Api(tags = {"公众号账号-管理后台"})
public class WxAccountController {

    @Autowired
    private WxAccountService wxAccountService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('wx:wxaccount:list')")
    @ApiOperation(value = "列表")
    public AjaxResult list(){
        List<WxAccount> list = wxAccountService.list();
        return AjaxResult.success(list);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{appid}")
    @PreAuthorize("@ss.hasPermi('wx:wxaccount:info')")
    @ApiOperation(value = "详情")
    public AjaxResult info(@PathVariable("id") String appid){
        WxAccount wxAccount = wxAccountService.getById(appid);
        return AjaxResult.success(wxAccount);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @PreAuthorize("@ss.hasPermi('wx:wxaccount:save')")
    @ApiOperation(value = "保存")
    public AjaxResult save(@RequestBody WxAccount wxAccount){
        wxAccountService.save(wxAccount);
        return AjaxResult.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{appids}")
    @PreAuthorize("@ss.hasPermi('wx:wxaccount:delete')")
    @ApiOperation(value = "删除")
    public AjaxResult delete(@PathVariable String[] appids){
        wxAccountService.removeByIds(Arrays.asList(appids));
        return AjaxResult.success();
    }



}
